package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.system.domain.Appmanager;
import com.ruoyi.system.mapper.AppmanagerMapper;
import com.ruoyi.system.service.IAppmanagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.AppinfoMapper;
import com.ruoyi.system.domain.Appinfo;
import com.ruoyi.system.service.IAppinfoService;

/**
 * 项目信息Service业务层处理
 * 
 * @author yaozh
 * @date 2024-03-04
 */
@Service
public class AppinfoServiceImpl implements IAppinfoService 
{
    @Autowired
    private AppinfoMapper appinfoMapper;
    @Autowired
    private IAppmanagerService appManagerService;
    @Autowired
    private AppmanagerMapper appmanagerMapper;

    /**
     * 查询项目信息
     * 
     * @param appid 项目信息主键
     * @return 项目信息
     */
    @Override
    public Appinfo selectAppinfoByAppid(Long appid,String dbName)
    {
        return appinfoMapper.selectAppinfoByAppid(appid,dbName);
    }

    /**
     * 查询项目信息列表
     * 
     * @param appinfo 项目信息
     * @return 项目信息
     */
    @Override
    public List<Appinfo> selectAppinfoList(Appinfo appinfo,String dbName)
    {
        return appinfoMapper.selectAppinfoList(appinfo,dbName);
    }

    /**
     * 新增项目信息
     * 
     * @param appinfo 项目信息
     * @return 结果
     */
    @Override
    public int insertAppinfo(Appinfo appinfo,String dbName)
    {
        String appName = appinfo.getAppname();
        Appmanager info = appmanagerMapper.checkAppNameUnique(appName);
        if(info != null){
            appinfo.setAppid(info.getAppid());
            appinfo.setAppname(info.getAppName());
        }else{
            return -2;
        }
        Appinfo tempAppInfo = appinfoMapper.selectAppinfoByAppid(info.getAppid(),dbName);
        if(tempAppInfo != null){
            return -3;
        }
        return appinfoMapper.insertAppinfo(appinfo,dbName);
    }

    /**
     * 修改项目信息
     * 
     * @param appinfo 项目信息
     * @return 结果
     */
    @Override
    public int updateAppinfo(Appinfo appinfo,String dbName)
    {
        return appinfoMapper.updateAppinfo(appinfo,dbName);
    }

    /**
     * 批量删除项目信息
     * 
     * @param appids 需要删除的项目信息主键
     * @return 结果
     */
    @Override
    public int deleteAppinfoByAppids(Long[] appids,String dbName)
    {
        return appinfoMapper.deleteAppinfoByAppids(appids,dbName);
    }

    /**
     * 删除项目信息信息
     * 
     * @param appid 项目信息主键
     * @return 结果
     */
    @Override
    public int deleteAppinfoByAppid(Long appid,String dbName)
    {
        return appinfoMapper.deleteAppinfoByAppid(appid,dbName);
    }
}
